package com.jiahao.material.mapper;


import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jiahao.material.entity.Warehouse;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.mapping.FetchType;

import java.util.List;
import java.util.Map;

public interface WarehouseMapper extends BaseMapper<Warehouse> {

    @Results(id = "warehouseMap",value = {
            @Result(id = true,column = "id",property = "id"),
            @Result(column = "name",property = "name"),
            @Result(column = "aid",property = "aid"),
            @Result(column = "address",property = "address"),
            @Result(column = "remarks",property = "remarks"),
            @Result(column = "createTime",property = "createTime"),
            @Result(column = "status",property = "status"),
            @Result(column = "updateTime",property = "updateTime"),
            @Result(column = "aid",property = "admin",one = @One(select = "com.jiahao.material.mapper.AdminMapper.selectById")),
            @Result(column = "id",property = "materials",many = @Many(select = "com.jiahao.material.mapper.MaterialMapper.getByWid"))
    })
    @Select({
            "<script>",
            "select * from warehouse ",
            "<where>",
            "<if test='map.name!=null and map.name !=\"\"'>and name like concat(concat('%',#{map.name},'%'))</if>",
            "<if test='map.aid!=null and map.aid !=\"\"'>and aid=#{map.aid}</if>",
            "<if test='map.status!=null and map.status !=\"\"'>and status=#{map.status}</if>",
            "</where>",
            "</script>"
    })
    public IPage<Warehouse> getByPage(Page<Warehouse> page, @Param("map")Map<String,Object> map);

    @ResultMap("warehouseMap")
    @Select("select * from warehouse")
    public List<Warehouse> getAll();
}
